home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Tools / ClassAct / Examples / Integer / IntegerExample.c < prev    next >
C/C++ Source or Header  |  1997-04-27  |  5KB  |  223 lines

  1. ;/* Integer Example
  2. sc link integerexample.c lib lib:classact.lib
  3. quit
  4. */
  5.  
  6. /**
  7.  **  IntegerExample.c -- Integer class Example.
  8.  **
  9.  **  This is a simple example testing some of the capabilities of the
  10.  **  Integer gadget class.
  11.  **
  12.  **  This code opens a window and then creates 2 Integer gadgets which
  13.  **  are subsequently attached to the window's gadget list.  One uses
  14.  **  arrows, one does not.  Notice that you can tab cycle between them.
  15.  **/
  16.  
  17. /* system includes
  18.  */
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22.  
  23. #include <exec/types.h>
  24. #include <exec/memory.h>
  25. #include <intuition/intuition.h>
  26. #include <intuition/gadgetclass.h>
  27. #include <graphics/gfxbase.h>
  28. #include <graphics/text.h>
  29. #include <graphics/gfxmacros.h>
  30. #include <utility/tagitem.h>
  31. #include <workbench/startup.h>
  32. #include <workbench/workbench.h>
  33.  
  34. #include <proto/intuition.h>
  35. #include <proto/graphics.h>
  36. #include <proto/exec.h>
  37. #include <proto/dos.h>
  38. #include <proto/utility.h>
  39. #include <proto/wb.h>
  40. #include <proto/icon.h>
  41.  
  42. /* ClassAct includes
  43.  */
  44. #include <classact.h>
  45.  
  46.  
  47. enum
  48. {
  49.     GID_MAIN=0,
  50.     GID_INTEGER1,
  51.     GID_INTEGER2,
  52.     GID_DOWN,
  53.     GID_UP,
  54.     GID_QUIT,
  55.     GID_LAST
  56. };
  57.  
  58. enum
  59. {
  60.     WID_MAIN=0,
  61.     WID_LAST
  62. };
  63.  
  64. enum
  65. {
  66.     OID_MAIN=0,
  67.     OID_LAST
  68. };
  69.  
  70. int main(void)
  71. {
  72.     struct MsgPort *AppPort;
  73.  
  74.     struct Window *windows[WID_LAST];
  75.  
  76.     struct Gadget *gadgets[GID_LAST];
  77.  
  78.     Object *objects[OID_LAST];
  79.  
  80.     /* make sure our classes opened... */
  81.     if (!ButtonBase || !IntegerBase || !WindowBase || !LayoutBase)
  82.         return(30);
  83.     else if ( AppPort = CreateMsgPort() )
  84.     {
  85.         /* Create the window object.
  86.          */
  87.         objects[OID_MAIN] = WindowObject,
  88.             WA_ScreenTitle, "ClassAct Release 2.0",
  89.             WA_Title, "ClassAct Integer Example",
  90.             WA_Activate, TRUE,
  91.             WA_DepthGadget, TRUE,
  92.             WA_DragBar, TRUE,
  93.             WA_CloseGadget, TRUE,
  94.             WA_SizeGadget, TRUE,
  95.             WINDOW_IconifyGadget, TRUE,
  96.             WINDOW_IconTitle, "Integer",
  97.             WINDOW_AppPort, AppPort,
  98.             WINDOW_Position, WPOS_CENTERMOUSE,
  99.             WINDOW_ParentGroup, gadgets[GID_MAIN] = VGroupObject,
  100.                 LAYOUT_SpaceOuter, TRUE,
  101.                 LAYOUT_DeferLayout, TRUE,
  102.  
  103.                 LAYOUT_AddChild, gadgets[GID_INTEGER1] = IntegerObject,
  104.                     GA_ID, GID_INTEGER1,
  105.                     GA_RelVerify, TRUE,
  106.                     GA_TabCycle, TRUE,
  107.                     INTEGER_Arrows, TRUE,
  108.                     INTEGER_MaxChars, 3,
  109.                     INTEGER_Minimum, -32,
  110.                     INTEGER_Maximum, 32,
  111.                     INTEGER_Number, 0,
  112.                 IntegerEnd,
  113.                 CHILD_NominalSize, TRUE,
  114.                 CHILD_Label, LabelObject, LABEL_Text, "Integer _1", LabelEnd,
  115.  
  116.                 LAYOUT_AddChild, gadgets[GID_INTEGER2] = IntegerObject,
  117.                     GA_ID, GID_INTEGER2,
  118.                     GA_RelVerify, TRUE,
  119.                     GA_TabCycle, TRUE,
  120.                     INTEGER_Arrows, FALSE,
  121.                     INTEGER_MaxChars, 6,
  122.                     INTEGER_Minimum, 0,
  123.                     INTEGER_Maximum, 100000,
  124.                     INTEGER_Number, 100,
  125.                 IntegerEnd,
  126.                 CHILD_Label, LabelObject, LABEL_Text, "Integer _2", LabelEnd,
  127.  
  128.                 LAYOUT_AddChild, ButtonObject,
  129.                     GA_ID, GID_QUIT,
  130.                     GA_RelVerify, TRUE,
  131.                     GA_Text,"_Quit",
  132.                 ButtonEnd,
  133.                 CHILD_WeightedHeight, 0,
  134.  
  135.             EndGroup,
  136.         EndWindow;
  137.  
  138.          /*  Object creation sucessful?
  139.           */
  140.         if (objects[OID_MAIN])
  141.         {
  142.             /*  Open the window.
  143.              */
  144.             if (windows[WID_MAIN] = (struct Window *) CA_OpenWindow(objects[OID_MAIN]))
  145.             {
  146.                 ULONG wait, signal, app = (1L << AppPort->mp_SigBit);
  147.                 ULONG done = FALSE;
  148.                 ULONG result;
  149.                 UWORD code;
  150.  
  151.                  /* Obtain the window wait signal mask.
  152.                  */
  153.                 GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);
  154.  
  155.                 /* Activate the first integer gadget!
  156.                  */
  157.                 ActivateLayoutGadget( gadgets[GID_MAIN], windows[WID_MAIN], NULL, gadgets[GID_INTEGER1] );
  158.  
  159.                 /* Input Event Loop
  160.                  */
  161.                 while (!done)
  162.                 {
  163.                     wait = Wait( signal | SIGBREAKF_CTRL_C | app );
  164.  
  165.                     if ( wait & SIGBREAKF_CTRL_C )
  166.                     {
  167.                         done = TRUE;
  168.                     }
  169.                     else
  170.                     {
  171.                         while ( (result = CA_HandleInput(objects[OID_MAIN], &code) ) != WMHI_LASTMSG )
  172.                         {
  173.                             switch (result & WMHI_CLASSMASK)
  174.                             {
  175.                                 case WMHI_CLOSEWINDOW:
  176.                                     windows[WID_MAIN] = NULL;
  177.                                     done = TRUE;
  178.                                     break;
  179.  
  180.                                 case WMHI_GADGETUP:
  181.                                     switch (result & WMHI_GADGETMASK)
  182.                                     {
  183.                                         case GID_QUIT:
  184.                                             done = TRUE;
  185.                                             break;
  186.                                     }
  187.                                     break;
  188.  
  189.                                 case WMHI_ICONIFY:
  190.                                     CA_Iconify(objects[OID_MAIN]);
  191.                                     windows[WID_MAIN] = NULL;
  192.                                     break;
  193.  
  194.                                 case WMHI_UNICONIFY:
  195.                                     windows[WID_MAIN] = (struct Window *) CA_OpenWindow(objects[OID_MAIN]);
  196.  
  197.                                     if (windows[WID_MAIN])
  198.                                     {
  199.                                         GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);
  200.                                     }
  201.                                     else
  202.                                     {
  203.                                         done = TRUE;    // error re-opening window!
  204.                                     }
  205.                                      break;
  206.                             }
  207.                         }
  208.                     }
  209.                 }
  210.             }
  211.  
  212.             /* Disposing of the window object will also close the window if it is
  213.              * already opened, and it will dispose of the layout object attached to it.
  214.              */
  215.             DisposeObject(objects[OID_MAIN]);
  216.         }
  217.  
  218.         DeleteMsgPort(AppPort);
  219.     }
  220.  
  221.     return(0);
  222. }
  223.